﻿<%@ Page Language="C#" MasterPageFile="../../main.master" Inherits="VioletDevelopmentLaboratory.Net.Web.PageBase" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			RolesListBound();
		}
	}

	private void RolesListBound()
	{
		Hashtable addGuestRolesHashtable = new Hashtable();
		addGuestRolesHashtable.Add("게스트(모든사용자)", DefaultRoles.Guest);
		addGuestRolesHashtable.Add("인증된사용자(모든역할포함)", DefaultRoles.Authenticated);

		Hashtable rolesHashtable = new Hashtable();
		rolesHashtable.Add("인증된사용자(모든역할포함)", DefaultRoles.Authenticated);
		
		if (Roles.Enabled)
		{
			String[] roles = Roles.GetAllRoles();

			foreach (String role in roles)
			{
				addGuestRolesHashtable.Add(role, role);
			}

			foreach (String role in roles)
			{
				rolesHashtable.Add(role, role);
			}
		}
		
	
		cbl_ListView.DataSource = addGuestRolesHashtable;
		cbl_ListView.DataTextField = "key";
		cbl_ListView.DataValueField = "value";
		cbl_ListView.DataBind();

		cbl_AnnoWrite.DataSource = rolesHashtable;
		cbl_AnnoWrite.DataTextField = "key";
		cbl_AnnoWrite.DataValueField = "value";
		cbl_AnnoWrite.DataBind();

		cbl_ThreadWrite.DataSource = rolesHashtable;
		cbl_ThreadWrite.DataTextField = "key";
		cbl_ThreadWrite.DataValueField = "value";
		cbl_ThreadWrite.DataBind();

		cbl_ThreadReplyWrite.DataSource = rolesHashtable;
		cbl_ThreadReplyWrite.DataTextField = "key";
		cbl_ThreadReplyWrite.DataValueField = "value";
		cbl_ThreadReplyWrite.DataBind();

		cbl_CommentWrite.DataSource = rolesHashtable;
		cbl_CommentWrite.DataTextField = "key";
		cbl_CommentWrite.DataValueField = "value";
		cbl_CommentWrite.DataBind();

		cbl_Read.DataSource = addGuestRolesHashtable;
		cbl_Read.DataTextField = "key";
		cbl_Read.DataValueField = "value";
		cbl_Read.DataBind();

		cbl_FileUpload.DataSource = rolesHashtable;
		cbl_FileUpload.DataTextField = "key";
		cbl_FileUpload.DataValueField = "value";
		cbl_FileUpload.DataBind();

		cbl_FileDownload.DataSource = addGuestRolesHashtable;
		cbl_FileDownload.DataTextField = "key";
		cbl_FileDownload.DataValueField = "value";
		cbl_FileDownload.DataBind();
	}

	protected void AddButton_Click(Object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			BoardCreateResult result = Board.Add(
				txt_ComponentId.Text,
				txt_Name.Text,
				cb_UseComment.Checked,
				cb_UseReply.Checked,
				cb_UseFileUpload.Checked,
				cb_UseStressNew.Checked,
				cb_UseStressToday.Checked,
				cb_UseStressHot.Checked,
				cb_UseListView.Checked,
				cb_UseVote.Checked,
				Int32.Parse(StressHotLimitTextBox.Text),
				Int32.Parse(txt_ThreadLimit.Text),
				Int32.Parse(PageSizeTextBox.Text),
				Int32.Parse(PageButtonCountTextBox.Text),
				Int32.Parse(FileUploadLimitTextBox.Text),
				Int32.Parse(FileUploadSizeLimitTextBox.Text),
				txt_FileUploadExtension.Text,
				Int32.Parse(ThumbnailWidthTextBox.Text),
				Int32.Parse(ThumbnailHeightTextBox.Text),
				ThumbnailSourceAspectRatio.Checked,
				GetCheckedRoles(cbl_ListView.Items),
				GetCheckedRoles(cbl_AnnoWrite.Items),
				GetCheckedRoles(cbl_ThreadWrite.Items),
				GetCheckedRoles(cbl_ThreadReplyWrite.Items),
				GetCheckedRoles(cbl_Read.Items),
				GetCheckedRoles(cbl_CommentWrite.Items),
				GetCheckedRoles(cbl_FileUpload.Items),
				GetCheckedRoles(cbl_FileDownload.Items),
				RequiredCategoryCheckBox.Checked
			);

			switch (result)
			{
				case BoardCreateResult.Success :
					VUtility.ShowMessagePanel(Page, txt_ComponentId.Text + "이(가) 추가되었습니다.", true);
					txt_ComponentId.Text = "";
					txt_Name.Text = "";
					break;
				default :
					VUtility.ShowMessagePanel(Page, "입력한 아이디를 가진 게시판이 존재합니다.", true);
					break;
			}
		}
	}

	protected void ComponentIDCheckButton_Click(object sender, EventArgs e)
	{
		String resultMessage = "";

		if (!String.IsNullOrEmpty(txt_ComponentId.Text))
		{
			if (Board.GetBoard(txt_ComponentId.Text) == null)
			{
				resultMessage = "사용가능한 아이디 입니다.";
			}
			else
			{
				resultMessage = "이미 사용중인 아이디 입니다.";
				txt_ComponentId.Text = "";
			}
		}
		else
		{
			resultMessage = "아이디를 입력하세요.";
		}

		VUtility.ShowMessagePanel(Page, resultMessage, true);
	}

	protected String GetCheckedRoles(ListItemCollection items)
	{
		String roles = "";

		foreach (ListItem item in items)
		{
			if (item.Selected)
			{
				roles += item.Value + "\r\n";
			}
		}

		return roles;
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPlaceHolder" runat="server">

	<h2>게시판 &gt; 추가</h2>

	<fieldset>
		<div class="Field">
			<div class="FieldName">아이디</div>
			<div class="FieldValue">
				<asp:TextBox ID="txt_ComponentId" runat="server" />
				<asp:RequiredFieldValidator ID="rfv_txt_ComponentId" runat="server" ControlToValidate="txt_ComponentId" Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
				<asp:Button ID="ComponentIDCheckButton" runat="server" CausesValidation="False" OnClick="ComponentIDCheckButton_Click" Text="중복확인" />
			</div>
		</div>
		<div class="Field">
			<div class="FieldName">이름</div>
			<div class="FieldValue">
				<asp:TextBox ID="txt_Name" runat="server" />
				<asp:RequiredFieldValidator ID="rfv_txt_Name" runat="server" ControlToValidate="txt_Name" Display="Dynamic" ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
			</div>
		</div>
		<div class="Field">
			<div class="FieldName">목록설정</div>
			<div class="FieldValue">
				목록글수 <asp:TextBox ID="PageSizeTextBox" runat="server" Text="20" MaxLength="3" Columns="3" /> |
				페이징 버튼수 <asp:TextBox ID="PageButtonCountTextBox" runat="server" Text="10" MaxLength="3" Columns="3" /> |
				<asp:CheckBox ID="cb_UseListView" runat="server" Checked="True" Text="글보기에서 목록출력" />
			</div>
		</div>
		<div class="Field">
			<div class="FieldName">글수제한</div>
			<div class="FieldValue"><asp:TextBox ID="txt_ThreadLimit" runat="server">-1</asp:TextBox> (-1 무제한)</div>
		</div>
		<div class="Field">
			<div class="FieldName">옵션</div>
			<div class="FieldValue">
				<div>
					<asp:CheckBox ID="cb_UseReply" runat="server" Text="답글" /> |
					<asp:CheckBox ID="cb_UseComment" runat="server" Checked="True" Text="댓글" /> |
					<asp:CheckBox ID="cb_UseVote" runat="server" Checked="false" Text="투표" />
				</div>
				<div>
					<asp:CheckBox ID="cb_UseStressToday" runat="server" Checked="True" Text="오늘글" /> |
					<asp:CheckBox ID="cb_UseStressNew" runat="server" Checked="True" Text="새글(24시간내)" /> |
					<asp:CheckBox ID="cb_UseStressHot" runat="server" Checked="True" Text="인기글" />
					<asp:TextBox ID="StressHotLimitTextBox" runat="server" MaxLength="3" Columns="3" Text="300" />Read이상
				</div>
				<div>
					<asp:CheckBox ID="RequiredCategoryCheckBox" runat="server" Text="글작성시 카테고리를 필수항목으로 설정" />
				</div>
			</div>
		</div>
		<div class="Field">
			<div class="FieldName">파일첨부</div>
			<div class="FieldValue">
				<div><asp:CheckBox ID="cb_UseFileUpload" runat="server" Text="사용하기" /></div>
				<div>
					첨부개수 <asp:TextBox ID="FileUploadLimitTextBox" runat="server" Text="1" Columns="3" MaxLength="3" />개 |
					최대파일크기 <asp:TextBox ID="FileUploadSizeLimitTextBox" runat="server" Text="1024" />KB
				</div>
				<div>첨부파일종류
					<asp:TextBox ID="txt_FileUploadExtension" runat="server" Width="40%">zip;jpg;jpeg;gif;png;wmv;wma;mp3;wav</asp:TextBox>
					<asp:RequiredFieldValidator ID="rfv_txt_FileUploadExtension" runat="server" ControlToValidate="txt_FileUploadExtension" Display="Dynamic" ErrorMessage="*" />
					(;세미콜론으로 구분, 예 : zip;jpg;gif)
				</div>
				<div>
					썸네일크기
					<asp:TextBox ID="ThumbnailWidthTextBox" runat="server" Width="100px">100</asp:TextBox>
					<asp:RequiredFieldValidator ID="ThumbnailWidthTextBoxRequiredFieldValidator" runat="server" 
						ControlToValidate="ThumbnailWidthTextBox" Display="Dynamic" 
						ErrorMessage="[썸네일가로]를 입력하세요." SetFocusOnError="True">*</asp:RequiredFieldValidator>
					<asp:CompareValidator ID="ThumbnailWidthTextBoxCompareValidator" runat="server" 
						ControlToValidate="ThumbnailWidthTextBox" Display="Dynamic" 
						ErrorMessage="[썸네일가로]는 정수로 입력하세요." Operator="DataTypeCheck" 
						SetFocusOnError="True" Type="Integer">*</asp:CompareValidator>
					X
					<asp:TextBox ID="ThumbnailHeightTextBox" runat="server" Width="100px">100</asp:TextBox>
					<asp:RequiredFieldValidator ID="ThumbnailHeightTextBoxRequiredFieldValidator" runat="server" 
						ControlToValidate="ThumbnailHeightTextBox" Display="Dynamic" 
						ErrorMessage="[썸네일세로]를 입력하세요." SetFocusOnError="True">*</asp:RequiredFieldValidator>
					<asp:CompareValidator ID="ThumbnailHeightTextBoxCompareValidator" 
						runat="server" ControlToValidate="ThumbnailHeightTextBox" Display="Dynamic" 
						ErrorMessage="[썸네일세로]는 정수로 입력하세요." Operator="DataTypeCheck" 
						SetFocusOnError="True" Type="Integer">*</asp:CompareValidator>
					<asp:CheckBox ID="ThumbnailSourceAspectRatio" runat="server" Text="원본비율유지하기" />
				</div>
			</div>
		</div>
		<div class="Field">
			<div class="FieldName">역할</div>
			<div class="FieldValue">
				<table border="0" cellspacing="0" cellpadding="5" width="100%">
					<tr>
						<td style="width : 90px;">목록보기</td>
						<td><asp:CheckBoxList ID="cbl_ListView" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>공지사항쓰기</td>
						<td><asp:CheckBoxList ID="cbl_AnnoWrite" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>글쓰기</td>
						<td><asp:CheckBoxList ID="cbl_ThreadWrite" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>답변쓰기</td>
						<td><asp:CheckBoxList ID="cbl_ThreadReplyWrite" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>댓글쓰기</td>
						<td><asp:CheckBoxList ID="cbl_CommentWrite" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>글보기</td>
						<td><asp:CheckBoxList ID="cbl_Read" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>파일첨부</td>
						<td><asp:CheckBoxList ID="cbl_FileUpload" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
					<tr>
						<td>파일받기</td>
						<td><asp:CheckBoxList ID="cbl_FileDownload" runat="server" CellPadding="3" 
								RepeatColumns="3" RepeatDirection="Horizontal" /></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="Field">
			<asp:Button ID="AddButton" runat="server" Text="추가" OnClick="AddButton_Click" />
		</div>
	</fieldset>
</asp:Content>